import com.flex.core.constants.GameConstants;
import com.flex.core.model.base.GameCanvas;
import com.flex.core.model.base.GameGridSprite;
import com.flex.core.model.base.GameUIComponent;
import com.flex.model.grid.GameGrid;

import mx.containers.Canvas;
import mx.controls.Alert;

/**
 * @author sam
 * this is a function for create gameGrid
 */ 

/**
 * create more grid 
 */
public function createMoreGrid(gameGrid:GameGridSprite,maxWidth:int,maxHeight:int):GameCanvas{
	var canvas:GameCanvas = new GameCanvas();
	var width:int = gameGrid.gridWidth;
	var height:int = gameGrid.gridHeight;
	var widthMultiple:int = (maxWidth / width);
	var heightMultiple:int = (maxHeight / height);
	maxWidth = widthMultiple * width;
	maxHeight = heightMultiple * height;
	return canvas;
}

/**
 * create one grid(base create function)
 *  *
 * ***
 *  *
 */ 
public function createOneGameGrid(gameGrid:GameGridSprite):GameUIComponent{
	var width:int = gameGrid.gridWidth;
	var height:int = gameGrid.gridHeight;
	var ui:GameUIComponent = new GameUIComponent();
	gameGrid.graphics.beginFill(0x999999);
	gameGrid.graphics.lineStyle(1,0xaaaaaa);
	gameGrid.graphics.moveTo(0,height/2);
	gameGrid.graphics.lineTo(width/2,0);
	gameGrid.graphics.lineTo(width,height/2);
	gameGrid.graphics.lineTo(width/2,height);
	gameGrid.graphics.lineTo(0,height/2);
	gameGrid.graphics.endFill();
	ui.addChild(gameGrid);
	return ui;
}

/**
 * create a quator grid,position rightUnder
 * **
 * *
 */ 
public function createRightDownQuaterGameGrid(gameGrid:GameGridSprite):GameUIComponent{
	var width:int = gameGrid.gridWidth;
	var height:int = gameGrid.gridHeight;
	var ui:GameUIComponent = createOneGameGrid(gameGrid);
	ui.width=width/2;
	ui.height=height/2;
	ui.x=-1;
	ui.y=-1;
	gameGrid.x=-width/2;
	gameGrid.y=-height/2;
	return ui;
}

/**
 * create a quator grid,position RightUp
 * *
 * **
 */ 
public function createRightUpQuaterGameGrid(gameGrid:GameGridSprite):GameUIComponent{
	var width:int = gameGrid.gridWidth;
	var height:int = gameGrid.gridHeight;
	var ui:GameUIComponent = createOneGameGrid(gameGrid);
	ui.width=width/2;
	ui.height=height/2;
	ui.x=-1;
	ui.y=-1;
	gameGrid.x=-width/2;
	gameGrid.y=0;
	return ui;
}

/**
 * create a quator grid,position LeftUp
 *  *
 * **
 */ 
public function createLeftUpQuaterGameGrid(gameGrid:GameGridSprite):GameUIComponent{
	var width:int = gameGrid.gridWidth;
	var height:int = gameGrid.gridHeight;
	var ui:GameUIComponent = createOneGameGrid(gameGrid);
	ui.width=width/2;
	ui.height=height/2;
	ui.x=-1;
	ui.y=-1;
	gameGrid.x=0;
	gameGrid.y=0;
	return ui;
}

/**
 * create a quator grid,position LeftDown
 * **
 *  *
 */ 
public function createLeftDownQuaterGameGrid(gameGrid:GameGridSprite):GameUIComponent{
	var width:int = gameGrid.gridWidth;
	var height:int = gameGrid.gridHeight;
	var ui:GameUIComponent = createOneGameGrid(gameGrid);
	ui.width=width/2;
	ui.height=height/2;
	ui.x=-1;
	ui.y=-1;
	gameGrid.x=0;
	gameGrid.y=-height/2;
	return ui;
}

/**
 * create a half grid,position Left
 *  *
 * **
 *  *
 */ 
public function createLeftHalfGameGrid(gameGrid:GameGridSprite):GameUIComponent{
	var width:int = gameGrid.gridWidth;
	var height:int = gameGrid.gridHeight;
	var ui:GameUIComponent = createOneGameGrid(gameGrid);
	ui.width=width/2;
	ui.height=height;
	ui.x=-1;
	ui.y=-1;
	gameGrid.x=0;
	gameGrid.y=0;
	return ui;
}

/**
 * create a half grid,position Right
 *  *
 *  **
 *  *
 */ 
public function createRightHalfGameGrid(gameGrid:GameGridSprite):GameUIComponent{
	var width:int = gameGrid.gridWidth;
	var height:int = gameGrid.gridHeight;
	var ui:GameUIComponent = createOneGameGrid(gameGrid);
	ui.width=width/2;
	ui.height=height;
	ui.x=-1;
	ui.y=-1;
	gameGrid.x=-width/2;
	gameGrid.y=0;
	return ui;
}

/**
 * create a half grid,position Up
 *   *
 *  ***
 */ 
public function createUpHalfGameGrid(gameGrid:GameGridSprite):GameUIComponent{
	var width:int = gameGrid.gridWidth;
	var height:int = gameGrid.gridHeight;
	var ui:GameUIComponent = createOneGameGrid(gameGrid);
	ui.width=width;
	ui.height=height/2;
	ui.x=-1;
	ui.y=-1;
	gameGrid.x=0;
	gameGrid.y=0;
	return ui;
}

/**
 * create a half grid,position Down
 *   *
 *  ***
 */ 
public function createDownHalfGameGrid(gameGrid:GameGridSprite):GameUIComponent{
	var width:int = gameGrid.gridWidth;
	var height:int = gameGrid.gridHeight;
	var ui:GameUIComponent = createOneGameGrid(gameGrid);
	ui.width=width;
	ui.height=height/2;
	ui.x=-1;
	ui.y=-1;
	gameGrid.x=0;
	gameGrid.y=-height/2;
	return ui;
}
